/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * StatusUI.java
 *
 * Created on Sep 9, 2012, 10:18:32 PM
 */

package com.apps.ui;

import com.apps.controllers.ShellController;
import com.apps.utils.StartupHelper;
import java.util.Map;
import javax.swing.JCheckBox;
import javax.swing.JLabel;

/**
 *
 * @author ARIJIT PAL
 */
public class StatusUI extends javax.swing.JPanel {

    private String accID;
    private ShellController shell;

    public ShellController getShell() {
        return shell;
    }

    public void setShell(ShellController shell) {
        this.shell = shell;
    }

    /** Creates new form StatusUI */
    public StatusUI() {
        initComponents();
        hostName.setSelected(true);
    }

    public String getAccID() {
        return accID;
    }

    public void setAccID(String accID) {
        this.accID = accID;
    }

    public String getHostName() {
        return hostName.getText();
    }

    public void setHostName(String hostName) {
        this.hostName.setText(hostName);
    }

    public boolean getActiveInd() {
        return hostName.isSelected()?true:false;
    }
    
    public void setActiveInd(boolean flag) {
        hostName.setSelected(flag);
    }
    
    public void setFlagCL(String cl){
        if(cl.equalsIgnoreCase("green")){
            statusCL.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/apps/ui/resources/green.png")));
        }else{
            statusCL.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/apps/ui/resources/red.png")));
        }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        statusCL = new javax.swing.JLabel();
        hostName = new javax.swing.JCheckBox();

        setMaximumSize(new java.awt.Dimension(32767, 46));

        statusCL.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/apps/ui/resources/red.png"))); // NOI18N

        hostName.setText("host1234abc.server.net");
        hostName.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                hostNameMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusCL)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(hostName)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(hostName)
                    .addComponent(statusCL))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void hostNameMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_hostNameMouseClicked
        // TODO add your handling code here:
        Map<String, ShellController> map = StartupHelper.getShellMap();
        ShellController shell = map.get(accID);
        if(shell != null){
            shell.setActiveFlag(getActiveInd());
        }
    }//GEN-LAST:event_hostNameMouseClicked


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox hostName;
    private javax.swing.JLabel statusCL;
    // End of variables declaration//GEN-END:variables

}
